package com.zb.excel.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.zb.constant.FinanceConstant;

/**
 * @Author WEN
 * @Date 2024/6/15 0015
 **/
public class WithdrawStatusToStringConverter implements Converter<Integer> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return Converter.super.supportJavaTypeKey();
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return Converter.super.supportExcelTypeKey();
    }

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return Converter.super.convertToJavaData(cellData, contentProperty, globalConfiguration);
    }

    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        return Converter.super.convertToJavaData(context);
    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String status = "";
        switch (value) {
            case FinanceConstant.WITHDRAW_STATUS_1 -> {
                status = FinanceConstant.WITHDRAW_STATUS_STR_1;
            }
            case FinanceConstant.WITHDRAW_STATUS_2 -> {
                status = FinanceConstant.WITHDRAW_STATUS_STR_2;
            }
            case FinanceConstant.WITHDRAW_STATUS_3 -> {
                status = FinanceConstant.WITHDRAW_STATUS_STR_3;
            }
            case FinanceConstant.WITHDRAW_STATUS_4 -> {
                status = FinanceConstant.WITHDRAW_STATUS_STR_4;
            }
            case FinanceConstant.WITHDRAW_STATUS_5 -> {
                status = FinanceConstant.WITHDRAW_STATUS_STR_5;
            }
        }
        return new WriteCellData<>(status);
    }

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> context) throws Exception {
        return Converter.super.convertToExcelData(context);
    }
}
